package com.lagou;

import org.apache.zookeeper.*;

/**
 * @author: jie.zhao
 * @create: 2021/05/31 15:34
 */
public class ZookeeperCreateNode {

    public String createNode(ZooKeeper zooKeeper,String data,String path) throws KeeperException, InterruptedException {

        String node = zooKeeper.create(path, data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
        return node;
    }

//    @Override
//    public void process(WatchedEvent watchedEvent) {
//        System.out.println("执行");
//    }

    public String createNode2(ZooKeeper zooKeeper,String data,String path) throws KeeperException, InterruptedException {

        String node = zooKeeper.create(path, data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        return node;
    }
}
